/*******************************************************************************
 * Copyright (c) 2015 btows.com.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package com.cleanwiz.applock.data.LookMyPrivateDao;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;

import com.cleanwiz.applock.data.LookMyPrivate;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table lookMyPrivate.
*/
public class LookMyPrivateDao extends AbstractDao<LookMyPrivate, Long> {

    public static final String TABLENAME = "lookMyPrivate";

    /**
     * Properties of entity LookMyPrivate.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property IsReaded = new Property(1, Boolean.class, "isReaded", false, "IS_READED");
        public final static Property LookDate = new Property(2, java.util.Date.class, "lookDate", false, "LOOK_DATE");
        public final static Property PicPath = new Property(3, String.class, "picPath", false, "PIC_PATH");
        public final static Property Resolver = new Property(4, String.class, "resolver", false, "RESOLVER");
    };


    public LookMyPrivateDao(DaoConfig config) {
        super(config);
    }
    
    public LookMyPrivateDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "'lookMyPrivate' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'IS_READED' INTEGER," + // 1: isReaded
                "'LOOK_DATE' INTEGER," + // 2: lookDate
                "'PIC_PATH' TEXT," + // 3: picPath
                "'RESOLVER' TEXT);"); // 4: resolver
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'lookMyPrivate'";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, LookMyPrivate entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Boolean isReaded = entity.getIsReaded();
        if (isReaded != null) {
            stmt.bindLong(2, isReaded ? 1l: 0l);
        }
 
        java.util.Date lookDate = entity.getLookDate();
        if (lookDate != null) {
            stmt.bindLong(3, lookDate.getTime());
        }
 
        String picPath = entity.getPicPath();
        if (picPath != null) {
            stmt.bindString(4, picPath);
        }
 
        String resolver = entity.getResolver();
        if (resolver != null) {
            stmt.bindString(5, resolver);
        }
    }

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    /** @inheritdoc */
    @Override
    public LookMyPrivate readEntity(Cursor cursor, int offset) {
        LookMyPrivate entity = new LookMyPrivate( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getShort(offset + 1) != 0, // isReaded
            cursor.isNull(offset + 2) ? null : new java.util.Date(cursor.getLong(offset + 2)), // lookDate
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // picPath
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // resolver
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, LookMyPrivate entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setIsReaded(cursor.isNull(offset + 1) ? null : cursor.getShort(offset + 1) != 0);
        entity.setLookDate(cursor.isNull(offset + 2) ? null : new java.util.Date(cursor.getLong(offset + 2)));
        entity.setPicPath(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setResolver(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(LookMyPrivate entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(LookMyPrivate entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
}
